#!/bin/sh
# inv_cli.sh: invidious viewer
# usage: inv_cli.sh <invidious url>

# instances are separated by spaces so a for loop can parse them as separate strings
# TODO: redirect to another instance if it fails
instances="yt.artemislena.eu inv.riverside.rocks vid.puffyan.us"
flags="-s -A 'Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0'"

# URL format: http[s]://$instance_domain/latest_version&itag=18&id=$id
id=`curl $flags $1 | grep 'itag=18' | cut -d '"' -f 2 | sed -n 1p`
url=`printf "https://yt.artemislena.eu%s\n" "$id"`
echo $id
mpv --user-agent='Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0' "$url"
